﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using System.Web;
using System.Web.Security;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class YuanlinSite : BaseSite
    {
        public override void CreateUser(System.Web.Core.MemberInfo memberInfo)
        {
            if (memberInfo != null)
            {
                YuanlinUser user = new YuanlinUser();
                Hashtable memberAttributes = memberInfo.MemberAttributes;

                user.MemberId.Value = memberInfo.MemberId;

                //Register information from the first register page.
                user.RegisterGreenNumber.Value = memberAttributes["RegisterGreenNumber"] as string;
                user.NickName.Value = memberAttributes["NickName"] as string;
                user.RecommendedUser.Value = memberAttributes["RecommendedUser"] as string;

                //Register information from the second register page.
                user.RealName.Value = memberAttributes["RealName"] as string;
                user.IdentityCardNumber.Value = memberAttributes["IdentityCardNumber"] as string;
                user.CompanyName.Value = memberAttributes["CompanyName"] as string;
                user.CompanyScale.Value = memberAttributes["CompanyScale"] as string;
                user.CompanyGoodSkill.Value = memberAttributes["CompanyGoodSkill"] as string;
                user.CompanyAddress.Value = memberAttributes["CompanyAddress"] as string;
                user.CompanyPostCode.Value = memberAttributes["CompanyPostCode"] as string;
                user.CompanyFixedTelephone1.Value = memberAttributes["CompanyFixedTelephone1"] as string;
                user.CompanyFixedTelephone2.Value = memberAttributes["CompanyFixedTelephone2"] as string;
                user.CompanyFaxNumber.Value = memberAttributes["CompanyFaxNumber"] as string;
                user.CompanyContactPhone.Value = memberAttributes["CompanyContactPhone"] as string;
                user.CompanyQQ.Value = memberAttributes["CompanyQQ"] as string;
                user.CompanySite.Value = memberAttributes["CompanySite"] as string;
                user.CompanyEmail.Value = memberAttributes["CompanyEmail"] as string;
                user.CompanyMSN.Value = memberAttributes["CompanyMSN"] as string;
                user.BankAccount.Value = memberAttributes["BankAccount"] as string;
                user.CompanyTypes.Value = memberAttributes["CompanyTypes"] as string;
                user.Business = memberAttributes["Business"] as string;
                user.ContactInfo = memberAttributes["ContactInfo"] as string;
                user.BankIndex.Value = Globals.ChangeType<int>(memberAttributes["BankIndex"]);
                user.Province.Value = Globals.ChangeType<int>(memberAttributes["Province"]);
                user.City.Value = Globals.ChangeType<int>(memberAttributes["City"]);
                user.Town.Value = Globals.ChangeType<int>(memberAttributes["Town"]);
                user.SmallTown.Value = Globals.ChangeType<int>(memberAttributes["SmallTown"]);

                //Register information from the third register page.
                user.Question1.Value = memberAttributes["Question1"] as string;
                user.Question1Answer.Value = memberAttributes["Question1Answer"] as string;
                user.Question2.Value = memberAttributes["Question2"] as string;
                user.Question2Answer.Value = memberAttributes["Question2Answer"] as string;
                user.PasswordProtectionNumber.Value = memberAttributes["PasswordProtectionNumber"] as string;
                user.RegisterDate.Value = Globals.ChangeType<DateTime>(memberAttributes["RegisterDate"]);

                user.CompanyDescription.Value = memberAttributes["CompanyDescription"] as string;
                user.Business = memberAttributes["Business"] as string;
                user.CompanyMachineChuShou = memberAttributes["CompanyMachineChuShou"] as string;
                user.CompanyMachineQiuGou = memberAttributes["CompanyMachineQiuGou"] as string;
                user.CompanyFacilityChuShou = memberAttributes["CompanyFacilityChuShou"] as string;
                user.CompanyFacilityQiuGou = memberAttributes["CompanyFacilityQiuGou"] as string;
                user.CompanyAgriculturalChuShou = memberAttributes["CompanyAgriculturalChuShou"] as string;
                user.CompanyAgriculturalQiuGou = memberAttributes["CompanyAgriculturalQiuGou"] as string;
                user.Certificate = memberAttributes["Certificate"] as string;
                user.SendMessage = memberAttributes["SendMessage"] as string;
                user.MyShopping = memberAttributes["MyShopping"] as string;
                user.CompanyBrand = memberAttributes["CompanyBrand"] as string;
                user.CompanyRecruit = memberAttributes["CompanyRecruit"] as string;
                user.CompanyAlbum = memberAttributes["CompanyAlbum"] as string;
                user.CompanyTechnology = memberAttributes["CompanyTechnology"] as string;
                user.CompanyProjectPerformance = memberAttributes["CompanyProjectPerformance"] as string;
                user.CompanyProject = memberAttributes["CompanyProject"] as string;
                user.CompanyNews = memberAttributes["CompanyNews"] as string;
                user.Huamu = memberAttributes["Huamu"] as string;
                user.Huamuqiugou = memberAttributes["Huamuqiugou"] as string;
                user.Huamujingpin = memberAttributes["Huamujingpin"] as string;
                user.Huamujishou = memberAttributes["Huamujishou"] as string;
                user.CompanyPartner = memberAttributes["CompanyPartner"] as string;
                user.CompanyFriend = memberAttributes["CompanyFriend"] as string;

                CreateUser(user);
            }
        }

        public override void DeleteUser(Guid memberId)
        {
            DeleteUser<YuanlinUser>(memberId);
        }

        public override void UpdateUserAttributes(Guid memberId, string attributeName, string attributeValue)
        {
            UpdateUserAttributes(GetUser<YuanlinUser>(memberId), attributeName, attributeValue);
        }
    }
}

